using System;
using System.Collections.Generic;
using System.Text;
using DataTools;
using DataTools.PagingUtils;
using ObjectLayer;

namespace AccessLayer
{
	public class fact_costs_revenues_targetDAO
{
		public static List<fact_costs_revenues_targetBO> GetAll()
		{
            ConnInfo.Db = "VNPT_Bsc";
			return CBO.FillCollection<fact_costs_revenues_targetBO>(DataProvider.getInstance().getAll(TableName.fact_costs_revenues_target, PagingHelper.CreateOrder(new OrderObject(fact_costs_revenues_targetTable.timekey, SortOrder.Desc))));
		}
		static object _Clock = new object();
		public static List<fact_costs_revenues_targetBO> GetAllC()
		{
            ConnInfo.Db = "VNPT_Bsc";
			List<fact_costs_revenues_targetBO> list = new List<fact_costs_revenues_targetBO>();
			if(DataCache.GetCache(CacheName.fact_costs_revenues_target) == null)
			{
				lock (_Clock)
				{
					if (DataCache.GetCache(CacheName.fact_costs_revenues_target) != null)
					{
						list = (List<fact_costs_revenues_targetBO>)DataCache.GetCache(CacheName.fact_costs_revenues_target);
					}
					else
					{
			list = CBO.FillCollection<fact_costs_revenues_targetBO>(DataProvider.getInstance().getAll(TableName.fact_costs_revenues_target, PagingHelper.CreateOrder(new OrderObject(fact_costs_revenues_targetTable.timekey, SortOrder.Desc))));
						DataCache.SetCache(CacheName.fact_costs_revenues_target, list);
					}
				}
			}
			else
			{
					list = (List<fact_costs_revenues_targetBO>)DataCache.GetCache(CacheName.fact_costs_revenues_target);
			}
		return list;
		}
		public static int InsertUpdateDelete(fact_costs_revenues_targetBO fact_costs_revenues_target, ProviderAction action)
        {
            ConnInfo.Db = "VNPT_Bsc";
			int rs = DataProvider.getInstance().InsertUpdateDelete(action, StoreProcedureName.InsertUpdateDelete_fact_costs_revenues_target, "@" + fact_costs_revenues_targetTable.cost_code, fact_costs_revenues_target.cost_code,fact_costs_revenues_target.unit,fact_costs_revenues_target.timekey,fact_costs_revenues_target.target,fact_costs_revenues_target.branch_code, DataTools.ConvertType.ToInt(action));
			if (rs != -1)
			{
				DataCache.RemoveCache(CacheName.fact_costs_revenues_target);
			}
			return rs;
		}
	}
}